package com.ste.server.command;

import com.ste.domain.Order;
import com.ste.domain.OrderBook;
import com.ste.server.Server;

public abstract class Trade {

	protected Server server;
	protected Command command;
	protected Order order;
	protected OrderType orderType;
	protected String stokeName;

	public Trade(Server server, Command command) {
		this.server = server;
		this.command = command;
		order = parseMessage(command.getMessage());
	}

	protected abstract Order parseMessage(String message);

	public void execute() {
		OrderBook orderBook = server.getOrderBooks().get(stokeName);
		if (orderBook == null){
			throw new NumberFormatException(order.getOrderId());
		}
		orderBook.addOrder(order);
	}

	public enum OrderType {
		BUY(1), SELL(2);
		public final Integer value;

		OrderType(Integer value) {
			this.value = value;
		}
	}
}
